const state={
	dropClassDialog: false,
	courseInfo:[]
};
const getters={
	
	isShow(state) {  //方法名随意,主要是来承载变化的selectClassDialog的值
       return state.dropClassDialog
   },
   getCourseInfo(state){
   	
   	   return state.courseInfo
   }
	
};

const mutations = {
	show(state) {//自定义改变state初始值的方法，这里面的参数除了state之外还可以再传额外的参数(变量或对象);
        state.dropClassDialog = true;
    },
    hide(state) {//同上
        state.dropClassDialog = false;
    },
    setCourseInfo(state,data){
    	
    	state.courseInfo=data;
    }
    
};

const actions = {
	hidedropClassPanel(context) {  //自定义触发mutations里函数的方法，context与store 实例具有相同方法和属性
        context.commit('hide');
    },
    showdropClassPanel(context) {  //同上注释
    	
        context.commit('show');
    },
    getCourseInfo(context,paras){  
    	let dicdata = tool.getItem(lsKey.dict,true)
		let chargeModes = dicdata["charge_mode"];
		let pay_mode=dicdata["pay_mode"];
		let course_time_mode=dicdata.course_time_mode;
    	// console.log(pay_mode)
    	api.getDropCoursePackageInfo(paras).then(function(data){   		
    		// console.log(data)
    		if(data.result=="操作成功"){
    			context.commit('show');
    			for(let i =0;i<data.info.length;i++){
    				
                    let mode = data.info[i].chargeMode+"";
                    let simpleprice = data.info[i].courseMoney/data.info[i].courseHour;
                    data.info[i].simpleprice=simpleprice.toFixed(2);
                    for(let j =0;j<chargeModes.length;j++){
                    	
                    	if(mode==chargeModes[j].value){
                    		data.info[i].chargeMode=chargeModes[j].name;
                    	}
                    	
					}
					
					data.info[i].methodradio='2';
					if(data.info[i].payMode==3||data.info[i].payMode==4){
						data.info[i].methodradio='100';
					}
					for(let j =0;j<pay_mode.length;j++){
						
                    	if(data.info[i].payMode==pay_mode[j].value){
                    		data.info[i].payMode=pay_mode[j].name;
                    	}
                    	
					}
					if(data.info[i].coursePackage.chargeMode==3){
						for(let j =0;j<course_time_mode.length;j++){
                    	
							if(data.info[i].coursePackage.courseTimeMode==course_time_mode[j].value){
								data.info[i].courseTimeMode=course_time_mode[j].name;
							}
							
						}
					}
					else{
						data.info[i].courseTimeMode='课时';
					}
					data.info[i].relMoney=data.info[i].needRefundMoney;
					data.info[i].maxMoney=data.info[i].needRefundMoney+0;
    			}   			
    			context.commit('setCourseInfo',data.info);
    		}
    	})
    }
};

module.exports = {
	  namespaced:true,//用于在全局引用此文件里的方法时标识这一个的文件名
	  state,
	  getters,
	  actions,
	  mutations
}